package se.wangs.observerpk.impl;

import se.wangs.observerpk.DisplayElement;
import se.wangs.observerpk.Observer;
import se.wangs.observerpk.Subject;
import se.wangs.observerpk.WeatherData;

/**
 * -- coding: UTF-8 -- *
 *
 * @author wangs
 * @date 2023/12/12 17:13
 * @description 一个具体的观察者
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {
    private Subject weatherData;
    private float temperature;
    private float humidity;
    private float pressure;

    public CurrentConditionsDisplay(WeatherData weatherData) {
        this.weatherData = weatherData;
        this.weatherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println("---------- CurrentConditionsDisplay ----------");
        System.out.println("temperature = " + temperature + "\n" +
                            "humidity = " + humidity + "\n" +
                            "pressure = " + pressure);
    }

    @Override
    public void update(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        // 更新数据后直接display
        display();
    }
}
